package com.example.moviegroup.adapter;

import android.content.Context;
import android.os.Environment;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.moviegroup.R;
import com.example.moviegroup.app.Logger;
import com.example.moviegroup.bean.FilmBean;
import com.example.moviegroup.utils.MyUrls;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by Xiaodong on 2015/11/18 0018.
 */
public class MyGridViewAdapter extends BaseAdapter{
    private  ArrayList<FilmBean.Film> list =new ArrayList<FilmBean.Film>();
    private  Context context;
    private BitmapUtils bitmapUtils;
    private File file;
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
            if(convertView==null){
                holder=new ViewHolder();
                convertView=View.inflate(context,R.layout.gv_item,null);
                holder.iv_image= (ImageView) convertView.findViewById(R.id.gv_item_iv_image);
                holder.tv_mvname= (TextView) convertView.findViewById(R.id.gv_item_tv_mvname);
               convertView.setTag(holder);
            }else{
                holder=(ViewHolder)convertView.getTag();
            }
        holder.tv_mvname.setText(list.get(position).film_name);
        holder.iv_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        BitmapDisplayConfig displayConfig = new BitmapDisplayConfig();
        //设置图片的大小
        // displayConfig.setBitmapMaxSize(new BitmapSize(400, 400));
        //设置图片下载过程中iv上显示的临时图片
//        displayConfig.setLoadingDrawable(context.getResources().getDrawable(R.mipmap.ic_launcher));
        //设置图片下载失败iv上显示的图片
        displayConfig.setLoadFailedDrawable(context.getResources().getDrawable(R.mipmap.ic_launcher));
//        AlphaAnimation animation=new AlphaAnimation(0.2f,1.0f);
//        animation.setDuration(500);
//        displayConfig.setAnimation(animation);
        Logger.d(MyUrls.MV_BASE + list.get(position).photo_url);
        bitmapUtils.display(holder.iv_image, MyUrls.MV_BASE + list.get(position).photo_url, displayConfig);
        return convertView;
    }
    class ViewHolder {
         ImageView iv_image;
        TextView tv_mvname;
    }
    public MyGridViewAdapter(Context context){
        this.context=context;
        file = new File(Environment.getExternalStorageDirectory()+File.separator+"MovieGroup");
        bitmapUtils=new BitmapUtils(context,file.getAbsolutePath(),100*1024*1024);
    }
    public void setList(ArrayList<FilmBean.Film> list){
        this.list=list;
    }


}
